# Create your views here.
import random
from string import ascii_letters, digits

def rnd_str(Length=16):
  '''
    Generates a string with random characters of Length 
  '''
  
  chars = tuple(ascii_letters + digits)
  return ''.join((random.choice(chars) for i in range(Length)))



class DictObj(dict):
  '''
  DictObj is a normal dictionary that allows you to access its members
  via the standard ``var[key]`` method as well as ``var.key``.
  '''
  def __init__(self,dic={}):
    dict.__init__(self,dic)
    self.__dict__ = self


def get_full_path(request):
  full_path = ('http', ('', 's')[request.is_secure()], '://', request.META['HTTP_HOST'], request.path)
  return ''.join(full_path)



def hexdump(prefix, src, length=16):
  HEX_FILTER=''.join([(len(repr(chr(x)))==3) and chr(x) or '.' for x in range(256)])

  N=0; result=''
  while src:
    s,src = src[:length],src[length:]
    hexa = ' '.join(["%02X"%ord(x) for x in s])
    s = s.translate(HEX_FILTER)
    result += "%s %04X   %-*s   %s\n" % (prefix, N, length*3, hexa, s)
    N+=length
  return result

